﻿@model PostViewModel
@{
    var post = Model.PostItem;
    var textClass = "post-text";
    if (Model.Summary)
    {
        textClass += " post-summary";
    }

    string commentsText = null;
    switch (post.Comments.Count())
    {
        case 0:
            commentsText = "No comments";
            break;
        case 1:
            commentsText = "1 comment";
            break;
        default:
            commentsText = post.Comments.Count() + " comments";
            break;
    }
}
<article id="post-id-@post.PostId" class="post">
    <header class="post-title">
        <h2>@Html.ActionLink(post.Title, "Index", new { controller = "Post", name = post.EncodedTitle })</h2>
        <span class="post-comments">@commentsText</span>
        <span class="post-author">@post.Creator.Name</span>
        <span class="post-created">@TimeZoneInfo.ConvertTimeFromUtc(post.Created, Request.GetClientTimeZone())</span>
    </header>
    @foreach (var tag in post.Tags)
    {
        <div class="post-tag">
            @Html.ActionLink(tag.Name, "Index", new { controller = "Tag", name = tag.EncodedName })
        </div>
    }
    <div class="@textClass">
        @if (Model.Summary)
        {
            @Html.Raw(post.Summary)
        }
        else
        { 
            @Html.Raw(post.Text)
        }
    </div>
    @if (Model.Summary)
    {
        <p class="post-more">
            @Html.ActionLink("Read More!", "Index", new { controller = "Post", name = post.EncodedTitle })
        </p>
    }
    else if (Request.IsAuthenticated)
    {
        <div>
            @Html.ActionLink("Edit", "Edit", new { area = "Admin", id = @post.PostId })
        </div>
    }
</article>
